<!--
* @Author: 张昊
* @Date:  2022-10-21 09:21:59
* @FilePath: /pages/mine/attestation/attestation.vue
* @Description: 教师认证
-->
<template>
	<view class="teacherCenter">
		<head-img />

		<view class="teacherCenterItem card">
			<u--form labelWidth="auto" labelPosition="left" :model="model" :rules="rules" ref="form1">
				<u-form-item label="教师姓名:" prop="userInfo.name" borderBottom ref="item1">
					<u--input v-model="model.userInfo.name" border="none" placeholder="请输入教师姓名"></u--input>
				</u-form-item>
				<u-form-item label="教师手机号:" prop="userInfo.mobile" borderBottom ref="item1">
					<u--input v-model="model.userInfo.mobile" border="none" placeholder="请输入教师手机号"></u--input>
				</u-form-item>
			</u--form>
			<view class="buttons">
				<view class="button1"><u-button type="primary" size="small" text="申请教师认证" @click="teacherCenterApi(model.userInfo)"></u-button></view>
			</view>
		</view>
	</view>
</template>

<script>
import { teacherCenter } from '@/common/api.js';
// 头像组件
import headImg from '@/components/content/head-img.vue';
export default {
	data() {
		return {
			model: {
				userInfo: {
					name: '',
					mobile: ''
				}
			},
			rules: {
				'userInfo.name': {
					type: 'string',
					required: true,
					message: '请填写姓名',
					trigger: ['blur', 'change']
				},
				'userInfo.mobile': {
					type: 'string',
					required: true,
					message: '请填写手机号',
					trigger: ['blur', 'change']
				}
			},
			// 获取验证码
			tips: '',

			seconds: 10,
			value: '',
			userData: null
		};
	},
	methods: {
		async teacherCenterApi() {
			let data = await teacherCenter({
				...this.model.userInfo
			});
			if (data) {
				console.log('绑定', data);
				data && uni.$u.toast('绑定成功');
				let userData = uni.getStorageSync('userData');
				uni.setStorageSync('userData', { ...userData, is_teacher: true });
				uni.navigateTo({
					url: '/pages/mine/mine'
				});
			} else {
			}
		}
	},
	components: {
		headImg
	},
	onShow() {
		if (uni.getStorageSync('userData')) {
			this.userData = uni.getStorageSync('userData');
			if (this.userData) {
				this.model.userInfo.mobile = this.userData.phoneNumber;
			}
		}
	}
};
</script>

<style lang="scss">
.teacherCenter {
	height: 100vh;
	// display: flex;
	// justify-content: center;
	// align-items: center;
	// flex-direction: column;
	.teacherCenterItem {
		width: 90%;
		padding: 28rpx;
	}
	.wrap {
		padding: 24rpx;
	}
	.form-item {
		display: flex;
		flex-direction: column;
	}
	.buttons {
		margin: 28 * 2rpx 28rpx;
		// width: 100vh;
		display: flex;
		justify-content: flex-end;
		.button1 {
			width: 200rpx;
			// height: 300rpx;
		}
	}
}
</style>
